package com.itheima.demo01;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class StreamDemo01 {
    public static void main(String[] args) {
        // Stream 收集方法

        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张骏然-男-14","李映婉-女-15","钱星思-女-13","王祥善-男-16","李雨林-男-14","赵娜羽-女-15","毛涛岸-男-17","张颂强-男-15","陈雨西-女-14","张萱锦-女-18");

        List<String> collect1 = list.stream().filter(s -> "男".equals(s.split("-")[1])).collect(Collectors.toList());
        System.out.println(collect1);

        Set<String> collect2 = list.stream().filter(s -> "男".equals(s.split("-")[1])).collect(Collectors.toSet());
        System.out.println(collect2);



        Map<String, Integer> collect3 = list.stream().filter(s -> "男".equals(s.split("-")[1])).collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.split("-")[0];
            }
        }, new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s.split("-")[2]);
            }
        }));

        System.out.println(collect3);


    }
}
